package com.regretbuying.front.service.goods.impl;

import com.regretbuying.front.dao.goods.GoodsDao;
import com.regretbuying.front.service.goods.GoodsService;
import com.regretbuying.pojo.Comment;
import com.regretbuying.pojo.Goods;
import com.regretbuying.pojo.Introduction;
import com.regretbuying.pojo.Specs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("fgsi")
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private GoodsDao goodsDao;

    @Override
    public List<Goods> findGoodsByParams(Map params) {
        return goodsDao.findGoodsByParams(params);
    }

    @Override
    public Goods findGoodsById(int id) {
        return goodsDao.findGoodsById(id);
    }

    @Override
    public Specs findSprcsById(int id, int goodsSpecs) {
        return goodsDao.findSprcsById(id,goodsSpecs);
    }

    @Override
    public List<Goods> getNewProductSelling() {
        Map params = new HashMap();
        params.put("sales",true);
        params.put("saleTime",true);
        params.put("size",10);
        params.put("goodsSpecs",true);

        List<Goods> goodsList = goodsDao.findGoodsByParams(params);
        return goodsList;
    }

    @Override
    public List<Goods> getNewRecommend(){
        Map params = new HashMap();
        params.put("recommend",true);
        params.put("sales",true);
        params.put("size",8);
        params.put("goodsSpecs",true);

        List<Goods> goodsList = goodsDao.findGoodsByParams(params);
        return goodsList;
    }

    @Override
    public List<Goods> getNewIfDiscounts() {
        Map params = new HashMap();
        params.put("ifdiscounts",true);
        params.put("sales",true);
        params.put("size",8);
        params.put("goodsSpecs",true);

        List<Goods> goodsList = goodsDao.findGoodsByParams(params);
        return goodsList;
    }

    @Override
    public List<Specs> getSpecsGoodsId(int id) {
        return goodsDao.findSpecsByGoodsId(id);
    }

    @Override
    public Introduction getIntroductionByGoodsId(int id) {
        return goodsDao.findIntroductionByGoodsId(id);
    }

    @Override
    public int getCountByGoodsId(int id) {
        int count = goodsDao.findCountByGoodsId(id);
        if(count > 0){
            return count;
        }
        return 0;
    }

    @Override
    public List<Comment> getCommentByGoodsId(int id) {
        return goodsDao.findCommentByGoodsId(id);
    }

}
